﻿namespace Smart.ERP
{
    using DevExpress.XtraEditors;
    using Smart.Common;
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class TRANS_REF
    {
        private bool m_Active;
        private decimal m_Amount;
        private string m_Branch_ID;
        private string m_Contract;
        private string m_Contract_ID;
        private string m_Currency_ID;
        private string m_Department_ID;
        private string m_Description;
        private decimal m_Discount;
        private string m_Employee_ID;
        private decimal m_ExchangeRate;
        private decimal m_FAmount;
        private decimal m_FDiscount;
        private string m_ID;
        private bool m_IsClose;
        private string m_Reason;
        private System.DateTime m_RefDate;
        private string m_RefID;
        private string m_RefOrgNo;
        private int m_RefType;
        private long m_Sorted;
        private string m_Stock_ID;
        private string m_TransFrom;
        private string m_TransTo;
        private string m_User_ID;

        public TRANS_REF()
        {
            this.m_ID = "";
            this.m_RefID = "";
            this.m_RefOrgNo = "";
            this.m_RefType = 0;
            this.m_RefDate = System.DateTime.Now;
            this.m_TransFrom = "";
            this.m_TransTo = "";
            this.m_Department_ID = "";
            this.m_Employee_ID = "";
            this.m_Stock_ID = "";
            this.m_Branch_ID = "";
            this.m_Contract_ID = "";
            this.m_Contract = "";
            this.m_Reason = "";
            this.m_Currency_ID = "";
            this.m_ExchangeRate = 0M;
            this.m_Amount = 0M;
            this.m_Discount = 0M;
            this.m_FAmount = 0M;
            this.m_FDiscount = 0M;
            this.m_IsClose = true;
            this.m_Sorted = 0L;
            this.m_Description = "";
            this.m_User_ID = "";
            this.m_Active = true;
        }

        public TRANS_REF(string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            this.m_ID = ID;
            this.m_RefID = RefID;
            this.m_RefOrgNo = RefOrgNo;
            this.m_RefType = RefType;
            this.m_RefDate = RefDate;
            this.m_TransFrom = TransFrom;
            this.m_TransTo = TransTo;
            this.m_Department_ID = Department_ID;
            this.m_Employee_ID = Employee_ID;
            this.m_Stock_ID = Stock_ID;
            this.m_Branch_ID = Branch_ID;
            this.m_Contract_ID = Contract_ID;
            this.m_Contract = Contract;
            this.m_Reason = Reason;
            this.m_Currency_ID = Currency_ID;
            this.m_ExchangeRate = ExchangeRate;
            this.m_Amount = Amount;
            this.m_Discount = Discount;
            this.m_FAmount = FAmount;
            this.m_FDiscount = FDiscount;
            this.m_IsClose = IsClose;
            this.m_Sorted = Sorted;
            this.m_Description = Description;
            this.m_User_ID = User_ID;
            this.m_Active = Active;
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo)
        {
            this.AddCombo(combo, this.LookUp());
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo, DataTable dt)
        {
            MyLib.TableToComboBox(combo, dt, "ID", "Name");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo)
        {
            this.AddComboAll(combo, "(Tất cả)");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo, string text)
        {
            DataTable table = new DataTable();
            table = this.LookUp();
            DataRow row = table.NewRow();
            row["ID"] = "All";
            row["Name"] = text;
            table.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, table, "ID", "Name");
        }

        public void AddComboDefault(System.Windows.Forms.ComboBox combo)
        {
            this.AddComboAll(combo, "(Mặc định)");
        }

        public int Count()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if (helper.Open() != "OK")
            {
                return 0;
            }
            int num = this.Count(helper.Connection);
            helper.Close();
            return num;
        }

        public int Count(SqlConnection myConnection)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteScalar(myConnection, "TRANS_REF_Count", 0);
        }

        public int Count(SqlTransaction myTransaction)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteScalar(myTransaction, "TRANS_REF_Count", 0);
        }

        public string CreateKey()
        {
            return this.CreateKey("");
        }

        public string CreateKey(SqlTransaction myTransaction)
        {
            return SqlHelper.GenCode(myTransaction, "");
        }

        public string CreateKey(string key)
        {
            return SqlHelper.GenCode(key);
        }

        public string CreateKey(SqlTransaction myTransaction, string key)
        {
            return SqlHelper.GenCode(myTransaction, key);
        }

        public bool Delete()
        {
            return this.Delete(this.m_ID);
        }

        public bool Delete(SqlConnection myConnection)
        {
            return this.Delete(myConnection, this.m_ID);
        }

        public bool Delete(SqlTransaction myTransaction)
        {
            return this.Delete(myTransaction, this.m_ID);
        }

        public bool Delete(string ID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Delete(helper.Connection, ID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Delete(SqlConnection myConnection, string ID)
        {
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "TRANS_REF_Delete", myParams, myValues) == "OK");
        }

        public bool Delete(SqlTransaction myTransaction, string ID)
        {
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "TRANS_REF_Delete", myParams, myValues) == "OK");
        }

        public string DeleteByID(SqlTransaction myTransaction, string Trans_ID)
        {
            string[] myParams = new string[] { "@RefID" };
            object[] myValues = new object[] { Trans_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "TRANS_REF_DeleteByID", myParams, myValues);
        }

        private void DispError(object sender, SqlHelperException e)
        {
            XtraMessageBox.Show(e.Message, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public bool Exist()
        {
            return this.Exist(this.m_ID);
        }

        public bool Exist(SqlTransaction myTransaction)
        {
            return this.Exist(myTransaction, this.m_ID);
        }

        public bool Exist(string ID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Exist(helper.Connection, ID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Exist(SqlConnection myConnection, string ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@RefID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "TRANS_REF_ExistByID", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                return hasRows;
            }
            helper.Close();
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return hasRows;
        }

        public bool Exist(SqlTransaction myTransaction, string ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@RefID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "TRANS_REF_ExistByID", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                return hasRows;
            }
            helper.RollBack(myTransaction);
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return hasRows;
        }

        public bool ExistByID()
        {
            return this.ExistByID(this.m_RefID);
        }

        public bool ExistByID(string ID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.ExistByID(helper.Connection, ID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool ExistByID(SqlConnection myConnection, string ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@RefID" };
            object[] myValues = new object[] { ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myConnection, "TRANS_REF_ExistByID", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
            }
            return hasRows;
        }

        public bool ExistByID(SqlTransaction myTransaction, string ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@RefID" };
            object[] myValues = new object[] { ID };
            SqlDataReader reader = new SqlHelper().ExecuteReader(myTransaction, "TRANS_REF_ExistByID", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                reader = null;
            }
            return hasRows;
        }

        public bool Get()
        {
            return this.Get(this.m_ID);
        }

        public bool Get(SqlConnection myConnection)
        {
            return this.Get(myConnection, this.m_ID);
        }

        public bool Get(SqlTransaction myTransaction)
        {
            return this.Get(myTransaction, this.m_ID);
        }

        public bool Get(string ID)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Get(helper.Connection, ID))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Get(SqlConnection myConnection, string ID)
        {
            bool flag = false;
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "TRANS_REF_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ID = Convert.ToString(reader["ID"]);
                    this.m_RefID = Convert.ToString(reader["RefID"]);
                    this.m_RefOrgNo = Convert.ToString(reader["RefOrgNo"]);
                    this.m_RefType = Convert.ToInt32(reader["RefType"]);
                    this.m_RefDate = Convert.ToDateTime(reader["RefDate"]);
                    this.m_TransFrom = Convert.ToString(reader["TransFrom"]);
                    this.m_TransTo = Convert.ToString(reader["TransTo"]);
                    this.m_Department_ID = Convert.ToString(reader["Department_ID"]);
                    this.m_Employee_ID = Convert.ToString(reader["Employee_ID"]);
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Branch_ID = Convert.ToString(reader["Branch_ID"]);
                    this.m_Contract_ID = Convert.ToString(reader["Contract_ID"]);
                    this.m_Contract = Convert.ToString(reader["Contract"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Currency_ID = Convert.ToString(reader["Currency_ID"]);
                    this.m_ExchangeRate = Convert.ToDecimal(reader["ExchangeRate"]);
                    this.m_Amount = Convert.ToDecimal(reader["Amount"]);
                    this.m_Discount = Convert.ToDecimal(reader["Discount"]);
                    this.m_FAmount = Convert.ToDecimal(reader["FAmount"]);
                    this.m_FDiscount = Convert.ToDecimal(reader["FDiscount"]);
                    this.m_IsClose = Convert.ToBoolean(reader["IsClose"]);
                    this.m_Sorted = Convert.ToInt64(reader["Sorted"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_User_ID = Convert.ToString(reader["User_ID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    flag = true;
                }
                reader.Close();
                reader = null;
                return flag;
            }
            helper.Close();
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return flag;
        }

        public bool Get(SqlTransaction myTransaction, string ID)
        {
            bool flag = false;
            string[] myParams = new string[] { "@ID" };
            object[] myValues = new object[] { ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "TRANS_REF_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ID = Convert.ToString(reader["ID"]);
                    this.m_RefID = Convert.ToString(reader["RefID"]);
                    this.m_RefOrgNo = Convert.ToString(reader["RefOrgNo"]);
                    this.m_RefType = Convert.ToInt32(reader["RefType"]);
                    this.m_RefDate = Convert.ToDateTime(reader["RefDate"]);
                    this.m_TransFrom = Convert.ToString(reader["TransFrom"]);
                    this.m_TransTo = Convert.ToString(reader["TransTo"]);
                    this.m_Department_ID = Convert.ToString(reader["Department_ID"]);
                    this.m_Employee_ID = Convert.ToString(reader["Employee_ID"]);
                    this.m_Stock_ID = Convert.ToString(reader["Stock_ID"]);
                    this.m_Branch_ID = Convert.ToString(reader["Branch_ID"]);
                    this.m_Contract_ID = Convert.ToString(reader["Contract_ID"]);
                    this.m_Contract = Convert.ToString(reader["Contract"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Currency_ID = Convert.ToString(reader["Currency_ID"]);
                    this.m_ExchangeRate = Convert.ToDecimal(reader["ExchangeRate"]);
                    this.m_Amount = Convert.ToDecimal(reader["Amount"]);
                    this.m_Discount = Convert.ToDecimal(reader["Discount"]);
                    this.m_FAmount = Convert.ToDecimal(reader["FAmount"]);
                    this.m_FDiscount = Convert.ToDecimal(reader["FDiscount"]);
                    this.m_IsClose = Convert.ToBoolean(reader["IsClose"]);
                    this.m_Sorted = Convert.ToInt64(reader["Sorted"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    this.m_User_ID = Convert.ToString(reader["User_ID"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    flag = true;
                }
                reader.Close();
                reader = null;
                return flag;
            }
            helper.RollBack(myTransaction);
            if (MyParamaters.IsShowWarning)
            {
                XtraMessageBox.Show(helper.Result, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return flag;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable("TRANS_REF_GetList");
        }

        public DataTable GetList(SqlConnection myConnection)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myConnection, "TRANS_REF_GetList");
        }

        public DataTable GetList(SqlTransaction myTransaction)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myTransaction, "TRANS_REF_GetList");
        }

        public DataTable GetList(System.DateTime from, System.DateTime to)
        {
            string[] myParams = new string[] { "@From", "@To" };
            object[] myValues = new object[] { from, to };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("TRANS_REF_GetList_ByDate", myParams, myValues);
        }

        public DataTable GetListByAll()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("TRANS_REF_GetListAll");
        }

        public DataTable GetProductHistory(string productid, string productName)
        {
            SqlHelper helper = new SqlHelper();
            string[] strArray = new string[] { "@ProductID", "@ProductName)" };
            object[] objArray = new object[] { "%" + productid + "%", "%" + productName + "%" };
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            helper.CommandType = CommandType.Text;
            string str2 = (("" + "SELECT     INVENTORY_DETAIL.RefDate, INVENTORY_DETAIL.RefNo, INVENTORY_DETAIL.RefType, INVENTORY_DETAIL.Product_ID, PRODUCT.Product_Name, " + "UNIT.Unit_Name, INVENTORY_DETAIL.Quantity, INVENTORY_DETAIL.UnitPrice, INVENTORY_DETAIL.Amount, INVENTORY_DETAIL.Stock_ID, ") + "INVENTORY_DETAIL.Customer_ID, INVENTORY_DETAIL.Employee_ID, INVENTORY_DETAIL.Description " + "FROM         INVENTORY_DETAIL INNER JOIN ") + "  PRODUCT ON INVENTORY_DETAIL.Product_ID = PRODUCT.Product_ID INNER JOIN " + "          UNIT ON PRODUCT.Unit = UNIT.Unit_ID ";
            string commandText = (str2 + " WHERE     (INVENTORY_DETAIL.Product_ID LIKE N'%" + productid + "%') AND (PRODUCT.Product_Name LIKE N'%" + productName + "%') ") + " ORDER BY INVENTORY_DETAIL.RefDate";
            return helper.ExecuteDataTable(commandText);
        }

        public bool Insert()
        {
            return this.Insert(this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Insert(SqlConnection myConnection)
        {
            return this.Insert(myConnection, this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Insert(SqlTransaction myTransaction)
        {
            return this.Insert(myTransaction, this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Insert(string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Insert(helper.Connection, ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Insert(SqlConnection myConnection, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Sorted", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "TRANS_REF_Insert", myParams, myValues) == "OK");
        }

        public bool Insert(SqlTransaction myTransaction, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Sorted", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "TRANS_REF_Insert", myParams, myValues) == "OK");
        }

        public DataTable LookUp()
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable("TRANS_REF_LookUp");
        }

        public string NewID()
        {
            return this.NewID("");
        }

        public string NewID(string key)
        {
            return SqlHelper.GenCode("TRANS_REF", "RefID", key);
        }

        public string NewID(SqlTransaction myTransaction, string key)
        {
            return SqlHelper.GenCode(myTransaction, "TRANS_REF", "RefID", key);
        }

        public DataTable Search(string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Contract, string Reason, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if (helper.Open() != "OK")
            {
                return null;
            }
            return this.Search(helper.Connection, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Contract, Reason, ExchangeRate, Amount, Discount, FAmount, FDiscount, IsClose, Description);
        }

        public DataTable Search(SqlConnection myConnection, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Contract, string Reason, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description)
        {
            string[] myParams = new string[] { "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Contract", "@Reason", "@ExchangeRate", "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Description" };
            object[] myValues = new object[] { "%" + RefOrgNo + "%", "%" + RefType + "%", "%" + RefDate + "%", "%" + TransFrom + "%", "%" + TransTo + "%", "%" + Contract + "%", "%" + Reason + "%", "%" + ExchangeRate + "%", "%" + Amount + "%", "%" + Discount + "%", "%" + FAmount + "%", "%" + FDiscount + "%", "%" + IsClose + "%", "%" + Description + "%" };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myConnection, "TRANS_REF_Search", myParams, myValues);
        }

        public DataTable Search(SqlTransaction myTransaction, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Contract, string Reason, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description)
        {
            string[] myParams = new string[] { "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Contract", "@Reason", "@ExchangeRate", "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Description" };
            object[] myValues = new object[] { "%" + RefOrgNo + "%", "%" + RefType + "%", "%" + RefDate + "%", "%" + TransFrom + "%", "%" + TransTo + "%", "%" + Contract + "%", "%" + Reason + "%", "%" + ExchangeRate + "%", "%" + Amount + "%", "%" + Discount + "%", "%" + FAmount + "%", "%" + FDiscount + "%", "%" + IsClose + "%", "%" + Description + "%" };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return helper.ExecuteDataTable(myTransaction, "TRANS_REF_Search", myParams, myValues);
        }

        public void SetData(string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            this.m_ID = ID;
            this.m_RefID = RefID;
            this.m_RefOrgNo = RefOrgNo;
            this.m_RefType = RefType;
            this.m_RefDate = RefDate;
            this.m_TransFrom = TransFrom;
            this.m_TransTo = TransTo;
            this.m_Department_ID = Department_ID;
            this.m_Employee_ID = Employee_ID;
            this.m_Stock_ID = Stock_ID;
            this.m_Branch_ID = Branch_ID;
            this.m_Contract_ID = Contract_ID;
            this.m_Contract = Contract;
            this.m_Reason = Reason;
            this.m_Currency_ID = Currency_ID;
            this.m_ExchangeRate = ExchangeRate;
            this.m_Amount = Amount;
            this.m_Discount = Discount;
            this.m_FAmount = FAmount;
            this.m_FDiscount = FDiscount;
            this.m_IsClose = IsClose;
            this.m_Sorted = Sorted;
            this.m_Description = Description;
            this.m_User_ID = User_ID;
            this.m_Active = Active;
        }

        public bool Update()
        {
            return this.Update(this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Update(SqlConnection myConnection)
        {
            return this.Update(this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Update(SqlTransaction myTransaction)
        {
            return this.Update(myTransaction, this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Sorted, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool Update(string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.Update(helper.Connection, ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool Update(SqlConnection myConnection, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Sorted", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "TRANS_REF_Update", myParams, myValues) == "OK");
        }

        public bool Update(SqlTransaction myTransaction, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, long Sorted, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Sorted", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Sorted, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "TRANS_REF_Update", myParams, myValues) == "OK");
        }

        public bool UpdateByID()
        {
            return this.UpdateByID(this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool UpdateByID(SqlConnection myConnection)
        {
            return this.UpdateByID(myConnection, this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool UpdateByID(SqlTransaction myTransaction)
        {
            return this.UpdateByID(myTransaction, this.m_ID, this.m_RefID, this.m_RefOrgNo, this.m_RefType, this.m_RefDate, this.m_TransFrom, this.m_TransTo, this.m_Department_ID, this.m_Employee_ID, this.m_Stock_ID, this.m_Branch_ID, this.m_Contract_ID, this.m_Contract, this.m_Reason, this.m_Currency_ID, this.m_ExchangeRate, this.m_Amount, this.m_Discount, this.m_FAmount, this.m_FDiscount, this.m_IsClose, this.m_Description, this.m_User_ID, this.m_Active);
        }

        public bool UpdateByID(string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description, string User_ID, bool Active)
        {
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            if ((helper.Open() == "OK") && this.UpdateByID(helper.Connection, ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, Amount, Discount, FAmount, FDiscount, IsClose, Description, User_ID, Active))
            {
                helper.Close();
                return true;
            }
            return false;
        }

        public bool UpdateByID(SqlConnection myConnection, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myConnection, "TRANS_REF_UpdateByID", myParams, myValues) == "OK");
        }

        public bool UpdateByID(SqlTransaction myTransaction, string ID, string RefID, string RefOrgNo, int RefType, System.DateTime RefDate, string TransFrom, string TransTo, string Department_ID, string Employee_ID, string Stock_ID, string Branch_ID, string Contract_ID, string Contract, string Reason, string Currency_ID, decimal ExchangeRate, decimal Amount, decimal Discount, decimal FAmount, decimal FDiscount, bool IsClose, string Description, string User_ID, bool Active)
        {
            string[] myParams = new string[] { 
                "@ID", "@RefID", "@RefOrgNo", "@RefType", "@RefDate", "@TransFrom", "@TransTo", "@Department_ID", "@Employee_ID", "@Stock_ID", "@Branch_ID", "@Contract_ID", "@Contract", "@Reason", "@Currency_ID", "@ExchangeRate", 
                "@Amount", "@Discount", "@FAmount", "@FDiscount", "@IsClose", "@Description", "@User_ID", "@Active"
             };
            object[] myValues = new object[] { 
                ID, RefID, RefOrgNo, RefType, RefDate, TransFrom, TransTo, Department_ID, Employee_ID, Stock_ID, Branch_ID, Contract_ID, Contract, Reason, Currency_ID, ExchangeRate, 
                Amount, Discount, FAmount, FDiscount, IsClose, Description, User_ID, Active
             };
            SqlHelper helper = new SqlHelper();
            helper.Error += new SqlHelper.ErrorEventHander(this.DispError);
            return (helper.ExecuteNonQuery(myTransaction, "TRANS_REF_UpdateByID", myParams, myValues) == "OK");
        }

        public string UpdateBySorted(SqlTransaction myTransaction, string ID, long Sorted)
        {
            string[] myParams = new string[] { "@ID", "@Sorted" };
            object[] myValues = new object[] { ID, Sorted };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "TRANS_REF_UpdateBySorted", myParams, myValues);
        }

        [Category("Column"), DisplayName("Active")]
        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        [DisplayName("Amount"), Category("Column")]
        public decimal Amount
        {
            get
            {
                return this.m_Amount;
            }
            set
            {
                this.m_Amount = value;
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return "2.5.0.0";
            }
        }

        [DisplayName("Branch_ID"), Category("Column")]
        public string Branch_ID
        {
            get
            {
                return this.m_Branch_ID;
            }
            set
            {
                this.m_Branch_ID = value;
            }
        }

        [Category("Column"), DisplayName("Contract")]
        public string Contract
        {
            get
            {
                return this.m_Contract;
            }
            set
            {
                this.m_Contract = value;
            }
        }

        [Category("Column"), DisplayName("Contract_ID")]
        public string Contract_ID
        {
            get
            {
                return this.m_Contract_ID;
            }
            set
            {
                this.m_Contract_ID = value;
            }
        }

        public string Copyright
        {
            get
            {
                return "C\x00f4ng Ty Phần Mềm Ho\x00e0n Hảo";
            }
        }

        [Category("Column"), DisplayName("Currency_ID")]
        public string Currency_ID
        {
            get
            {
                return this.m_Currency_ID;
            }
            set
            {
                this.m_Currency_ID = value;
            }
        }

        [Category("Column"), DisplayName("Department_ID")]
        public string Department_ID
        {
            get
            {
                return this.m_Department_ID;
            }
            set
            {
                this.m_Department_ID = value;
            }
        }

        [DisplayName("Description"), Category("Column")]
        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        [DisplayName("Discount"), Category("Column")]
        public decimal Discount
        {
            get
            {
                return this.m_Discount;
            }
            set
            {
                this.m_Discount = value;
            }
        }

        [DisplayName("Employee_ID"), Category("Column")]
        public string Employee_ID
        {
            get
            {
                return this.m_Employee_ID;
            }
            set
            {
                this.m_Employee_ID = value;
            }
        }

        [Category("Column"), DisplayName("ExchangeRate")]
        public decimal ExchangeRate
        {
            get
            {
                return this.m_ExchangeRate;
            }
            set
            {
                this.m_ExchangeRate = value;
            }
        }

        [Category("Column"), DisplayName("FAmount")]
        public decimal FAmount
        {
            get
            {
                return this.m_FAmount;
            }
            set
            {
                this.m_FAmount = value;
            }
        }

        [DisplayName("FDiscount"), Category("Column")]
        public decimal FDiscount
        {
            get
            {
                return this.m_FDiscount;
            }
            set
            {
                this.m_FDiscount = value;
            }
        }

        [DisplayName("ID"), Category("Primary Key")]
        public string ID
        {
            get
            {
                return this.m_ID;
            }
            set
            {
                this.m_ID = value;
            }
        }

        [Category("Column"), DisplayName("IsClose")]
        public bool IsClose
        {
            get
            {
                return this.m_IsClose;
            }
            set
            {
                this.m_IsClose = value;
            }
        }

        public string Product
        {
            get
            {
                return "Class TRANS_REF";
            }
        }

        [Category("Column"), DisplayName("Reason")]
        public string Reason
        {
            get
            {
                return this.m_Reason;
            }
            set
            {
                this.m_Reason = value;
            }
        }

        [Category("Column"), DisplayName("RefDate")]
        public System.DateTime RefDate
        {
            get
            {
                return this.m_RefDate;
            }
            set
            {
                this.m_RefDate = value;
            }
        }

        [Category("Column"), DisplayName("RefID")]
        public string RefID
        {
            get
            {
                return this.m_RefID;
            }
            set
            {
                this.m_RefID = value;
            }
        }

        [Category("Column"), DisplayName("RefOrgNo")]
        public string RefOrgNo
        {
            get
            {
                return this.m_RefOrgNo;
            }
            set
            {
                this.m_RefOrgNo = value;
            }
        }

        [DisplayName("RefType"), Category("Column")]
        public int RefType
        {
            get
            {
                return this.m_RefType;
            }
            set
            {
                this.m_RefType = value;
            }
        }

        [Category("Column"), DisplayName("Sorted")]
        public long Sorted
        {
            get
            {
                return this.m_Sorted;
            }
            set
            {
                this.m_Sorted = value;
            }
        }

        [Category("Column"), DisplayName("Stock_ID")]
        public string Stock_ID
        {
            get
            {
                return this.m_Stock_ID;
            }
            set
            {
                this.m_Stock_ID = value;
            }
        }

        [Category("Column"), DisplayName("TransFrom")]
        public string TransFrom
        {
            get
            {
                return this.m_TransFrom;
            }
            set
            {
                this.m_TransFrom = value;
            }
        }

        [DisplayName("TransTo"), Category("Column")]
        public string TransTo
        {
            get
            {
                return this.m_TransTo;
            }
            set
            {
                this.m_TransTo = value;
            }
        }

        [Category("Column"), DisplayName("User_ID")]
        public string User_ID
        {
            get
            {
                return this.m_User_ID;
            }
            set
            {
                this.m_User_ID = value;
            }
        }
    }
}

